﻿using CowsAndBulls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace TestCowsAndBulls
{

    [TestClass()]
    public class ComputerTest
    {
        [TestMethod()]
        public void CheckNumberTest()
        {
            Computer target = new Computer(); // TODO: Initialize to an appropriate value
            int[] number = null; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.CheckNumber(number);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        [TestMethod()]
        public void GenerateNumberTest()
        {
            Computer target = new Computer(); // TODO: Initialize to an appropriate value
            Nullable<int> seed = new Nullable<int>(); // TODO: Initialize to an appropriate value
            target.GenerateNumber(seed);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        [TestMethod()]
        public void ResetAttemptsTest()
        {
            Computer target = new Computer(); // TODO: Initialize to an appropriate value
            target.ResetAttempts();

            Assert.AreEqual(1, target.Attempts);
        }

        [TestMethod()]
        public void ResetCheatsTest()
        {
            Computer target = new Computer(); // TODO: Initialize to an appropriate value
            target.ResetCheats();

            Assert.AreEqual(0, target.Cheats);
            for (int i = 0; i < target.IsShowed.Length; i++)
            {
                Assert.AreEqual(false, target.IsShowed[i]);
            }
        }

        [TestMethod()]
        public void ShowBullTestOnce()
        {
            Computer target = new Computer(); // TODO: Initialize to an appropriate value
            target.GenerateNumber(42);
            string result = target.ShowBull();
            string generatedNumber = "6115";

            Assert.AreEqual(4, result.Length);

            int nonX = 0;
            for (int i = 0; i < result.Length; i++)
            {
                if (result[i] != 'X')
                {
                    nonX++;
                    Assert.AreEqual(generatedNumber[i], result[i]);
                }
            }
            Assert.AreEqual(1, nonX);
        }


        [TestMethod()]
        public void ShowBullTestFiveTimes()
        {
            Computer target = new Computer(); // TODO: Initialize to an appropriate value
            target.GenerateNumber(42);
            string result;

            for (int i = 0; i < 4; i++)
            {
                result = target.ShowBull();
                string generatedNumber = "6115";
                Assert.AreEqual(4, result.Length);

                int nonX = 0;
                for (int j = 0; j < result.Length; j++)
                {
                    if (result[j] != 'X')
                    {
                        nonX++;
                        Assert.AreEqual(generatedNumber[j], result[j]);
                    }
                }
                Assert.AreEqual(1, nonX);
            }

            result = target.ShowBull();
            Assert.AreEqual("GAME OVER! You have tryed to cheat for the fifth time, which means that you are an idiot!",
                result);

        }
    }
}
